package com.sen.controller;


import com.sen.entity.Resource;
import com.sen.result.Result;
import com.sen.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sen
 * @since 2021-03-29
 */
@Api(tags = "资源控制器")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @ApiOperation(value = "查询资源信息")
    @GetMapping("/{id}")
    public Result getResourceById(@PathVariable Integer id){
        return resourceService.getResourceById(id);
    }

    @ApiOperation(value = "新增资源")
    @PostMapping
    public Result addResource(@RequestBody Resource resource){
        Result result = resourceService.saveResource(resource);
        return result;
    }

    @ApiOperation(value = "查询所有资源")
    @GetMapping("/list/{cur}/{size}")
    public Result listResource(@PathVariable Integer cur, @PathVariable Integer size){
        Result result = resourceService.getResourceList(cur, size);
        return result;
    }

    @ApiOperation(value = "修改资源信息")
    @PutMapping
    public Result updateResource(@RequestBody Resource resource){
        Result result = resourceService.updateResource(resource);
        return result;
    }

    @ApiOperation(value = "删除资源")
    @DeleteMapping("/{id}")
    public Result deleteResource(@PathVariable Integer id){
        Result result = resourceService.deleteResourceById(id);
        return result;
    }

}
